package com.crissy.messageService.controller;

import com.crissy.messageService.common.Result;
import com.crissy.messageService.entity.Message;
import com.crissy.messageService.entity.MessageDTO;
import com.crissy.messageService.service.IMessageService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Crissy-月下闲人
 * @since 2024-03-29
 */
@RestController
@CrossOrigin
@RequestMapping("/message")
public class MessageController {
    @Resource
    private IMessageService messageService;

    @PostMapping("/toSubmit")
    public Result<String> toSubmit(@RequestBody MessageDTO message) {
        return messageService.toSubmit(message.getMessage(), message.get__message());
    }

    @GetMapping("/toSearch")
    public Result<List<Message>> toSearch(@RequestParam String keyword) {
        return messageService.toSearch(keyword);
    }

    @GetMapping("/toFindById")
    public Result<Message> toFindById(@RequestParam("id") Long id) {
        return messageService.toFindById(id);
    }

    @GetMapping("/toDeleteById")
    public Result<String> toDeleteById(@RequestParam("id") Long id) {
        return messageService.toDeleteById(id);
    }

    @GetMapping("/toFindByPhone")
    public Result<List<Message>> toFindByPhone(@RequestParam("phone") String phone) {
        return messageService.toFindByPhone(phone);
    }


    @GetMapping("/toFindByIdNumber")
    public Result<List<Message>> toFindByIdNumber(@RequestParam("idNumber") String idNumber) {
        return messageService.toFindByIdNumber(idNumber);
    }
}
